<template>
  <view class="coursesLearned">
    <view class="history_header acea-row">
      <text>共{{ courses.length }}条，最多为您保存100条</text>
    </view>
    <coursesLearned :courses="courses"></coursesLearned>
  </view>
</template>

<script>
import coursesLearned from "../../../components/homeIndex/coursesLearned.vue";
import {
  mapGetters
} from "vuex";
import {browseRecordApi} from "../../../api/user";
export default {
  name: "index",
  components:{
    coursesLearned
  },
  data(){
    return{
      courses:[],
      propagation:{
        limit:10,
        page:1,
      }
    }
  },
  computed: mapGetters(['isLogin']),
  // onReachBottom(){
  //   if (this.isLogin) {
  //     this.getList()
  //   }
  // },
  onShow: function () {
    if (this.isLogin) {
      this.getList()
    }
  },
  methods:{
    getList(){
      browseRecordApi().then(res=>{
        const mergedList = res.data.reduce((acc, item) => {
          return acc.concat(item.list);
        }, []);
        this.courses=mergedList
      })
    }
  }
}
</script>

<style scoped lang="scss">
.coursesLearned{
  padding: 15px;

  .history_header {
    justify-content: space-between;
    margin: 30rpx 0;

    text {
      font-size: 26rpx;
      color: #666666;
    }

    .text {
      color: var(--view-theme);
    }
  }
}
</style>